<?php
//
// parcelforce licencing module
// Copyright 2009 2010 Philip Clarke
// Copyright 2009 2010 Bouncing Ltd
//

  require('includes/application_top.php');

  $pfrm = new pfrm_licence;

   if(isset($_POST['fu'])){

    $sql = "UPDATE `".TABLE_CONFIGURATION."` SET last_modified=FROM_UNIXTIME(0) WHERE configuration_key='MODULE_PFRM_REGISTERED'";

    $db->Execute($sql);

//     print $sql;

    header('Location: '.$_SERVER['PHP_SELF']);
    exit;

   }

   if(isset($_POST['pfrmupdate'])){

    $yes_list = array();
    $no_list = array();

    foreach($pfrm->auto_update_possibility as $key=>$val){

      if(isset($_POST[$key])){
	$yes_list[] = $key;
      }else{
	$no_list[] = $key;
      }

    }

    $pfrm->yes_no_list = array($yes_list, $no_list);

    $sql = "UPDATE ".TABLE_CONFIGURATION." SET configuration_value='True' WHERE configuration_key IN ('".join('\', \'', $yes_list)."')";

//     print $sql;

    $db->Execute($sql);

    $sql = "UPDATE ".TABLE_CONFIGURATION." SET configuration_value='False' WHERE configuration_key IN ('".join('\', \'', $no_list)."')";

//     print $sql;

    $db->Execute($sql);

    header('Location: sqlupdates_licence.php');


  }


  $action = (isset($_GET['action']) ? $_GET['action'] : ($_POST['action']) ? $_POST['action'] : '');

  $action = htmlentities($action);

  $systestmsg = 'Not testing yet.';

  switch ($action){

    case 'register':

      $str = 'key='.$_POST['licence_key'];

      $pfrm->connect('register.php', array('key'=>$_POST['licence_key']));


    break;

    case 'systest':

      $pfrm->connect('testconn.php');

      if(!isset($pfrm->html[0]) || sizeof($pfrm->html[0])==0){
	$systestmsg = 'System Test failed, this server is not suitable for licencing. Please contact us for further details.';
      }else{
	$systestmsg = join('', $pfrm->html[0]);
      }

    break;

  }

// print nl2br(print_r(get_included_files(), true));

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript">
  <!--
  function init()
  {
    cssjsmenu('navbar');
    if (document.getElementById)
    {
      var kill = document.getElementById('hoverJS');
      kill.disabled = true;
    }
  }
  // -->
</script>
<style type="text/css">
  .pfrmerr{font-weight: bold; color:red;}
</style>
</head>
<body onload="init()">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr>
<!-- body_text //-->
    <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
            <td class="pageHeading">ParcelForce Worldwide / Royal Mail Licencing Module version <?php echo $pfrm->version ; ?></td>
            <td class="pageHeading" align="right"><?php echo zen_draw_separator('pixel_trans.gif', HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
	<td class="pfrmerr">
	<?php
	   if(sizeof($pfrm->errors)>0){
	      print "<p>";
	      print join('</p><p>', $pfrm->errors);
	      print "</p>";
	   }
	?>
	</td>
      </tr>
<?php
  if(!defined('MODULE_PFRM_LICENCENO')){
?>
      <tr>
	<td>
	<p>The Parcelforce and RoyalMail modules are free and GPL Licenced.  The <u>shipping rates included with the modules is example data only</u> and in some cases dates from 2007 price lists.</p>

	<p>The modules can be downloaded from <a href="http://shop.exploitingIT.co.uk/" target="_blank">http://shop.exploitingIT.co.uk/</a>, licences can also be purchased there.</p>

	<p><strong>You always have the option of going to the the Royal Mail or ParcelForce websites, downloading the spreadsheets and pdf's entering the data yourself</strong>. <em>However</em>, since a year long subscription only costs &pound;<?php echo MODULE_PFRM_PRICE ; ?> (per service, price correct January 2010), it depends how much you value your time (and how many times a year you are prepared to spend hours in front of a computer typing/ cutting and pasting, kilograms, pounds and pence).</p>
	<p>A licence allows a yearly subscription to download shipping rate updates. Upon purchase of a licence this server will connect to our server and install the SQL patches needed to give your customers the correct and best prices.</p>

	<h3>Why this is important.</h3>

	<p>ParcelForce used to release price changes every year from the 1st January. Suddenly in October 2009 they released a new set of rates, varying in some cases by &pound;20. The rate updates are available for ParcelForce Worldwide, Royal Mail UK, and Royal Mail Airmail services.</p>

	<h3>Benefits.</h3>

	<ul>
	  <li>We don't need to access your shop admin (with the old system we did as we'd need to install the SQL patch manually)</li>
	  <li>Rates will almost certainly change twice in your subscription year so the first year is effectively half the previous price</li>
	  <li>As long as you have set the rates to update, then you will never be caught short</li>
	  <li>You can choose not to install rates for which ever shipping service</li>
	  <li>The system also tells you if your shipping modules need updating (they are GPL and free but it's nice to know that you will be running the latest up to date software).</li>
	</ul>

	<p>The system checks every at a maximum rate of once every 12 hours for new updates on installed modules when you log into admin, you also force an update if you add a new shipping service and the 12 hour check has already happened, giving you total control.</p>

	<h3>System Test</h3>
	<p>This shop will need to communicate with the outside world to download rates. Clicking the button below will try and establish contact.</p>
	<form action="<?php echo zen_href_link('sqlupdates_licence.php') ;?>" method="POST">
	<input type="hidden" name="action" value="systest" />
	<input type="submit" value="Test suitability" />
	</form>
<?php
  if(isset($_POST['action']) && $_POST['action']=='systest'){
?>
	<h4>System Test results.</h4>
	<p><? echo $systestmsg ; ?></p>
<?php
  }
?>
	</td>
      </tr>
<?php
  }
?>
      <tr>
	<td>
	<h2>Privacy.</h2>
	<p>If you have bought this module you will have received a licence number. You click on register and that sends the licence to this server along with the your host name and ip address we requires the hostname of the server as many different domain names may be assigned to one address for example in shared hosting or domain parking.</p>

	<p>This shop will send <ul><li>the shop's ip address</li><li>a unique identifier</li><li>the shop's host name</li></ul> about the same as a session cookie being sent to a web browser. In return it will send back <ul><li>confirmation of any version updates needed.</li><li>SQL patches to the rates which it will install.</li></ul></p>

	<p>The licence is valid per shop, <strong>If you change your ip address or move domains</strong> (even including if you move folders since you may be running more than one shop on the same domain name), this module will stop working until you inform us. As the serial number is locked to your domain, results are unpredictable if the licence is used with another hostname. The serial number remains property of Bouncing Limited at all times (like your credit card or gas/ water meter).</p>

	<p>If the licence is invalid or expires the update facility, (not the shipping modules) will not function. <strong>Customers are still able to purchase items and pay for shipping</strong> at whichever rate was last on the system.</p>
      	</td>
      </tr>
      <tr>
        <td>

<?php
  if(defined('MODULE_PFRM_REGISTERED') && defined ('MODULE_PFRM_LICENCENO')){

      $pfrm->connect('regpulldown.php', array('key'=>MODULE_PFRM_LICENCENO));

?>
  <h2>Licenced.</h2>

  <p>Licence Number: <?php echo MODULE_PFRM_LICENCENO ; ?></p>
<?php
	  print join("\n",$pfrm->html[0]);
?>
  <h3>Support.</h3>

  <p>Support is no longer given at the Zen Cart forums, instead temporarily please email <a href="mailto:royal@exploitingIT.co.uk">royal@exploitingIT.co.uk</a></p>

  <h3>Update configuration.</h3>

  <p>By default your rates do not update. You may have changed some rates for a special purpose (like you've added some extra to the rates to cover having to file CN22 custom's paperwork). It's best not to do this and to use the handling fee configuration in each module, but just in case we start by not overwriting your rates until you confirm that you wish to update.</p>

  <p>
  <ul>
    <li>Your shop is set to query our server for updated rates at a maximum of 12 hour interval when you log into admin.</li>
    <li>If you do not log in, then currently the rates do not update.</li>
    <li>If you have installed a shipping service and ticked the box then your rates for that module will automatically be updated should any newer versions become available.</li>
    <li>If you have not ticked the box for an installed service, a message will be displayed at the top of your admin screen to kepp you informed that a newer version is available.</li>
  </ul>
  </p>

  <p>Modules can only be updated if they are <em>"installed"</em>, (yellow or green dot by them in shipping), they do not have to be <em>"enabled"</em> so you can install them, update them, check the rates, shipping, handling etc... and then enable them to send them live, that way your customers do not ever get partailly filled out information.</p>

<?php

      if(sizeof($pfrm->errors)>0){

	  print "<div class=\"pfrmerr\"><p>";
	  print join('</p><p>', $pfrm->errors);
	  print "</p></div>";

      }else{
	  print join("\n",$pfrm->html[1]);
	  print join("\n",$pfrm->html[2]);
      }

?>


<?php

  }else{

?>

<h2>Register</h2>

<form action="<?php echo zen_href_link('sqlupdates_licence.php') ;?>" method="POST">
  <input type="hidden" name="action" value="register" />
  <label for="licence_key"></label><input type="text" name="licence_key" id="licence_key" />
  <input type="submit" value="Register" />
</form>

<?php
  }
?>

</td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>